package com.windgo.controller.admin;

import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.vo.*;
import com.windgo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author doublec
 * @since 2022/10/12 15:52
 */

@RestController
@RequestMapping("admin/config")
public class AdminConfigController {
    @Autowired
    AdminService adminService;

    @RequestMapping(value = "mall", method = RequestMethod.GET)
    public BaseRespVo<MallInfoVO> mallGET() {
        MallInfoVO mallInfoVO = adminService.mallInfo();

        return BaseRespVo.ok(mallInfoVO);
    }

    @RequestMapping(value = "mall", method = RequestMethod.POST)
    public RespInfoVO mallPOST(@RequestBody MallInfoVO mallInfoVO) {
        int affectedRows = adminService.updateMallConfig(mallInfoVO);
        RespInfoVO mallConfigUpdateVO;
        if (affectedRows == 1) {
            mallConfigUpdateVO = new RespInfoVO(0, "成功");
        } else {
            mallConfigUpdateVO = new RespInfoVO(500, "失败");
        }
        return mallConfigUpdateVO;
    }

    @RequestMapping(value = "express", method = RequestMethod.GET)
    public BaseRespVo<ExpressInfoVO> expressGET() {
        ExpressInfoVO expressInfoVO = adminService.expressInfo();
        return BaseRespVo.ok(expressInfoVO);
    }

    @RequestMapping(value = "express", method = RequestMethod.POST)
    public RespInfoVO expressPOST(@RequestBody ExpressInfoVO expressInfoVO) {
        int affectedRows = adminService.updateExpressConfig(expressInfoVO);
        RespInfoVO expressConfigUpdateVO;
        if (affectedRows == 1) {
            expressConfigUpdateVO = new RespInfoVO(0, "成功");
        } else {
            expressConfigUpdateVO = new RespInfoVO(500, "失败");
        }
        return expressConfigUpdateVO;
    }

    @RequestMapping(value = "order", method = RequestMethod.GET)
    public BaseRespVo<OrderInfoVO> orderGET() {
        OrderInfoVO orderInfoVO = adminService.orderInfo();
        return BaseRespVo.ok(orderInfoVO);
    }

    @RequestMapping(value = "order", method = RequestMethod.POST)
    public RespInfoVO orderPOST(@RequestBody OrderInfoVO orderInfoVO) {
        int affectedRows = adminService.updateOrderConfig(orderInfoVO);
        RespInfoVO orderConfigUpdateVO;
        if (affectedRows == 1) {
            orderConfigUpdateVO = new RespInfoVO(0, "成功");
        } else {
            orderConfigUpdateVO = new RespInfoVO(500, "失败");
        }
        return orderConfigUpdateVO;
    }

    @RequestMapping(value = "wx", method = RequestMethod.GET)
    public BaseRespVo<WxInfoVO> wxGET() {
        WxInfoVO wxInfoVO = adminService.wxInfo();
        return BaseRespVo.ok(wxInfoVO);
    }

    @RequestMapping(value = "wx", method = RequestMethod.POST)
    public RespInfoVO wxPOST(@RequestBody WxInfoVO wxInfoVO) {
        int affectedRows = adminService.updateWxConfig(wxInfoVO);
        RespInfoVO wxConfigUpdateVO;
        if (affectedRows == 1) {
            wxConfigUpdateVO = new RespInfoVO(0, "成功");
        } else {
            wxConfigUpdateVO = new RespInfoVO(500, "失败");
        }
        return wxConfigUpdateVO;
    }
}